var e = require;
var t = module;
var o = exports;
var ii, nn = this && this.__extends || (ii = function (t, e) {
    return (ii = Object.setPrototypeOf || {
        __proto__: []
    }
        instanceof Array &&
        function (t, e) {
            t.__proto__ = e
        } ||
        function (t, e) {
            for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
        })(t, e)
},
    function (t, e) {
        function o() {
            this.constructor = t
        }
        ii(t, e),
            t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
    }
),
    rr = this && this.__awaiter ||
        function (t, e, o, i) {
            return new (o || (o = Promise))(function (n, a) {
                function r(t) {
                    try {
                        l(i.next(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function s(t) {
                    try {
                        l(i.
                            throw(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function l(t) {
                    var e;
                    t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
                        t(e)
                    })).then(r, s)
                }
                l((i = i.apply(t, e || [])).next())
            })
        };
var oo = (this && this.__decorate) ||
    function (e, t, a, n) {
        var i,
            o = arguments.length,
            s = o < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, a)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, a, n);
        else
            for (var r = e.length - 1; r >= 0; r--)
                (i = e[r]) && (s = (o < 3 ? i(s) : o > 3 ? i(t, a, s) : i(t, a)) || s);
        return o > 3 && s && Object.defineProperty(t, a, s), s;
    }; Object.defineProperty(o, "__esModule", { value: !0 });
var a = e("NotifyEventType"),
    n = e("GlobalParams"),
    i = e("AssetsManager"),
    r = e("AudioManager"),
    s = e("ModuleUI"),
    l = e("CommonHelper"),
    _ = e("RoleSoldierInfo"),
    c = e("sdkConfig"),
    d = e("AD"),
    h = e("Toast"),
    u = e("BigAdNative"),
    p = e("BuyEquipInfo"),
    m = cc._decorator,
    f = m.ccclass,
    v = m.property,
    g = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.revive_time_label = null),
                (t.hero_card_list = []),
                (t.revive_num_label = null),
                (t.hero_view_node = null),
                (t.big_native_node = null),
                t
            );
        }
        return (
            nn(t, e),
            (t.prototype.initView = function () {
                var t = this;
                e.prototype.initView.call(this),
                    d.default.getInstance().getGameTestVersion() && d.default.getInstance().showInter(),
                    d.default.getInstance().hideBanner(),
                    c.default.platform == c.EPlatform.TikTok &&
                    (d.default.getInstance().PauseRecorder(), d.default.getInstance().showBanner());
                var o = n.GlobalParams.PlayerInfo.value;
                (this.revive_num_label.string = "x" + o.revive),
                    this.showReviveInfo(),
                    (this.hero_view_node.active =
                        c.default.platform != c.EPlatform.NO_AD &&
                        !d.default.getInstance().getGameTestVersion() &&
                        !n.GlobalParams.PlayGuideMode),
                    c.default.platform != c.EPlatform.OPPO || d.default.getInstance().getGameTestVersion()
                        ? ((this.hero_card_list[1].active = !0), (this.big_native_node.active = !1))
                        : ((this.hero_card_list[1].active = !1),
                            (this.big_native_node.active = !0),
                            this.big_native_node.getComponent(u.default).showNativeCall(function () {
                                t.hero_card_list[1].active = !0;
                            }));
            }),
            (t.prototype.addEvent = function () {
                this.attachEvent(a.default.SEND_GAME_OVER_INFO, this.showGameOver, this),
                    cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP, this.onKeyUp, this);
            }),
            (t.prototype.onKeyUp = function (e) {
                switch ((cc.log("=====keyCode======", e.keyCode), e.keyCode)) {
                    case cc.macro.KEY.y:
                        this.videoRevive();
                        break;
                    case cc.macro.KEY.u:
                        this.reviveInfo();
                        break;
                    case cc.macro.KEY.q:
                        this.useHeroInfo(0);
                        break;
                    case cc.macro.KEY.e:
                        this.useHeroInfo(1);
                }
            }),
            (t.prototype.showGameOver = function () {
                this.closePopup();
            }),
            (t.prototype.showReviveTime = function (e) {
                this.revive_time_label.string = "" + Math.ceil(e / 10);
            }),
            (t.prototype.showReviveInfo = function () {
                for (
                    var e = this,
                    t = function (t) {
                        var a = n.GlobalParams.ReviveHeroInfo[t],
                            r = _.default.Role_info[a.hero_id];
                        (o.hero_card_list[t].getChildByName("hero_name").getComponent(cc.Sprite).spriteFrame =
                            i.default.getInstance().getHeroHeadFrame("hero_name_" + r.id)),
                            o.uiManager.getRoleSkele(r.id, function (o) {
                                (e.hero_card_list[t].getChildByName("hero").getComponent(sp.Skeleton).skeletonData =
                                    o),
                                    e.hero_card_list[t]
                                        .getChildByName("hero")
                                        .getComponent(sp.Skeleton)
                                        .setAnimation(0, "battle_idle", !0);
                            }),
                            (o.hero_card_list[t].getChildByName("hero_type").getComponent(cc.Label).string =
                                0 == r.C_type ? "近战英雄" : "远程英雄"),
                            (o.hero_card_list[t].getChildByName("use_btn_" + t).children[0].active = a.is_video);
                    },
                    o = this,
                    a = 0;
                    a < 2;
                    a++
                )
                    t(a);
            }),
            (t.prototype.OnClick = function (t) {
                e.prototype.OnClick.call(this, t);
                var o = t.node.name;
                switch (o) {
                    case "video_btn":
                        this.videoRevive();
                        break;
                    case "revive_btn":
                        this.reviveInfo();
                        break;
                    case "use_btn_0":
                    case "use_btn_1":
                        var a = Number(l.default.getNameType(o, "use_btn_"));
                        this.useHeroInfo(a);
                }
            }),
            (t.prototype.useHeroInfo = function (e) {
                var t = this;
                n.GlobalParams.ReviveHeroInfo[e].is_video
                    ? d.default.getInstance().showVideo(function (o) {
                        if ((r.default.playGameBGM(), o == d.ResultEnum.Success)) {
                            t.useReviveHero(e);
                            for (var a = 0; a < n.GlobalParams.PlayingRoleDie.length; a++)
                                n.GlobalParams.PlayingRoleDie[a].role_index == n.GlobalParams.MatchMyIndex &&
                                    (n.GlobalParams.PlayingRoleDie[a].cound_down = 1);
                        }
                    })
                    : this.useReviveHero(e);
            }),
            (t.prototype.reviveInfo = function () {
                if (n.GlobalParams.PlayerInfo.value.revive > 0) {
                    this.uiManager.addFhbNum(-1);
                    for (var e = 0; e < n.GlobalParams.PlayingRoleDie.length; e++)
                        n.GlobalParams.PlayingRoleDie[e].role_index == n.GlobalParams.MatchMyIndex &&
                            (n.GlobalParams.PlayingRoleDie[e].cound_down = 1);
                } else h.default.showNewToast("复活币不足");
            }),
            (t.prototype.videoRevive = function () {
                var e = this;
                d.default.getInstance().showVideo(function (t) {
                    if ((r.default.playGameBGM(), t == d.ResultEnum.Success))
                        for (var o = 0; o < n.GlobalParams.PlayingRoleDie.length; o++)
                            n.GlobalParams.PlayingRoleDie[o].role_index == n.GlobalParams.MatchMyIndex &&
                                (e.uiManager.addFhbNum(3), (n.GlobalParams.PlayingRoleDie[o].cound_down = 1));
                });
            }),
            (t.prototype.useReviveHero = function (e) {
                var t = n.GlobalParams.MatchGamePlayer[n.GlobalParams.MatchMyIndex],
                    o = t.role_id,
                    i = n.GlobalParams.ReviveHeroInfo[e];
                (t.role_id = i.hero_id), (i.hero_id = o), (i.is_video = !1), (n.GlobalParams.ReviveHeroInfo[e] = i);
                var r = _.default.Role_info[t.role_id],
                    s = p.default.getPlayerInit();
                (s.attack = r.C_attack + r.C_attack_up * t.level),
                    (s.skill_1 = r.S1_attack + r.S1_attack_up * t.skill_info[0]),
                    (s.skill_2 = r.S2_attack + r.S2_attack_up * t.skill_info[1]),
                    (s.skill_3 = r.S3_attack + r.S3_attack_up * t.skill_info[2]),
                    (s.hp = r.C_hp + r.C_hp_up * t.level),
                    (s.move_speed = 24),
                    (s.attack_speed = 1),
                    (s.cool_1 = _.default.Hore_Skill_Info[t.role_id].one_time),
                    (s.cool_2 = _.default.Hore_Skill_Info[t.role_id].two_time),
                    (s.cool_3 = _.default.Hore_Skill_Info[t.role_id].three_time),
                    0 == t.dower_info[0]
                        ? (s.attack += t.dower_info[1])
                        : 1 == t.dower_info[0]
                            ? (s.move_speed += t.dower_info[1])
                            : 2 == t.dower_info[0]
                                ? (s.hp += t.dower_info[1])
                                : 3 == t.dower_info[0]
                                    ? (s.attack_speed -= t.dower_info[1])
                                    : 4 == t.dower_info[0] && ((s.cool_1 -= t.dower_info[1]), (s.cool_2 -= t.dower_info[1])),
                    (n.GlobalParams.GamePlayerInfo[n.GlobalParams.MatchMyIndex] = s),
                    this.emitEvent(a.default.SEND_UPDATE_PLAYER_REVIVE_INFO),
                    this.showReviveInfo();
            }),
            (t.prototype.closeThisPopup = function () {
                d.default.getInstance().showBanner(), this.node.destroy();
            }),
            oo([v(cc.Label)], t.prototype, "revive_time_label", void 0),
            oo([v(cc.Node)], t.prototype, "hero_card_list", void 0),
            oo([v(cc.Label)], t.prototype, "revive_num_label", void 0),
            oo([v(cc.Node)], t.prototype, "hero_view_node", void 0),
            oo([v(cc.Node)], t.prototype, "big_native_node", void 0),
            oo([f], t)
        );
    })(s.default);
o.default = g;
